using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using PccCommonForC;
public partial class Manager_ProductStore_ProductStoreDetailInDay : System.Web.UI.Page
{

    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["AdminUserID"] == null)
        {
            Response.Write("<script language=javascript>alert('Time is out.');window.open('../Default.aspx','_top');</script>");
            return;
        }
        if (!IsPostBack)
            BindData();
    }

    private void BindData()
    {
        if (Request.QueryString["PDID"] != "" && Request.QueryString["PDID"] != null)
        {
            PccMsg msg = new PccMsg();
            string sEndDate = Request.QueryString["EndDate"] ;
            if (sEndDate == "" || sEndDate == null)
                sEndDate = Request.QueryString["StartDate"];
            msg.CreateFirstNode("PdID", Request.QueryString["PDID"]);
            msg.CreateFirstNode("StartDate", Request.QueryString["StartDate"]);
            msg.CreateFirstNode("EndDate", sEndDate);
            msg.CreateFirstNode("StID", Request.QueryString["StID"]); 
            clsWebShop cls = new clsWebShop();
            DataSet ds = cls.Get_Store_ProductByConditionInDay(msg.GetXmlStr);
            if (ds.Tables[0].Rows.Count > 0)
            {              
                grv_Master.DataSource = ds;
                grv_Master.DataBind();

                decimal vTotal = 0;

                for(int i=0;i<grv_Master.Rows.Count;i++)
                {
                    if (grv_Master.Rows[i ].FindControl("lblInput") == null) continue;
                    Label lblInputNext = (Label)grv_Master.Rows[i ].FindControl("lblInput");
                    Label lblOutputNext = (Label)grv_Master.Rows[i ].FindControl("lblOutput");
                    Label lblTotal = (Label)grv_Master.Rows[i].FindControl("lblTotal");

                    if (lblInputNext.Text != null && lblInputNext.Text != "")
                    {
                        vTotal += decimal.Parse(lblInputNext.Text);
                    }
                    if (lblOutputNext.Text != null && lblOutputNext.Text != "")
                    {
                        vTotal -= decimal.Parse(lblOutputNext.Text);
                    }

                    lblTotal.Text = vTotal.ToString();

                }
            }

        }

    }
    protected void btnSearch_Click(object sender, EventArgs e)
    {
        BindData();
    }
    protected void grv_Master_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            clsCommon cls = new clsCommon();       
            e.Row.Cells[1].Text = cls.FormatDateTime(e.Row.Cells[1].Text);
        }
    }

    private string FormatDate(string sDate)
    {
        string sReturn = "";
        try
        {
            sReturn = sDate.ToString().Substring(6, 2) + "/" + sDate.ToString().Substring(4, 2) + "/" + sDate.ToString().Substring(0, 4);
        }
        catch (Exception ex) { }

        return sReturn;
    }
}
